import _CRCJS from "./_CRCStuff.js"

var ToiletoState = {};

//操作控制寄存器状态
ToiletoState.T50To80 = function()
{
    var ReciverData = window.hilink.getStorageSync("ReciverData");
}

//检测寄存器状态
ToiletoState.T0To40 = function()
{

}
//设置 整个寄存器的值00001
public boolean setRegisterValue(int slaveAddr, int regAddr, int regValue) {
    if (!ApplicationXpClient.isConnect())
        return false;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(regValue);
    mCommandQueue.offer(obj);
    return true;
}
//设置高8位
public void setRegisterHighValue(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0x00ff) | ((regValue << 8) & 0xff00);
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}
//设置低8位
public void setRegisterLowValue(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0xff00) | ((regValue) & 0x00ff);
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}

//设置马桶0-3位的值
public void setRegister4LowValuebefore(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0xfff0) | ((regValue) & 0x000f);
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);

}

//设置马桶4-7位的值
public void setRegister4LowValue(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0xff0f) | ((regValue << 4) & 0x00f0);
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}

//设置马桶8—11位的值
public void setRegister4HighValuebefore(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0xf0ff) | ((regValue << 8));
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}

//设置马桶12-15位的值
public void setRegister4HighValue(int slaveAddr, int regAddr, int regValue) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    curValue = (curValue & 0x0fff) | ((regValue << 12));
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}

/**
 * 设置寄存器单次位的值
 *
 * @param slaveAddr
 * @param regAddr
 * @param regBit
 * @param val
 */

public void setRegisterBitValue(int slaveAddr, int regAddr, int regBit, int val) {
    int curValue = getRegisterValue(slaveAddr, regAddr);
    if (val == 1)
        curValue |= (int) (1 << regBit);
    else
        curValue &= ~(1 << regBit);
    if (!ApplicationXpClient.isConnect())
        return;
    ToiletCommandObject obj = new ToiletCommandObject();
    obj.setAddress(regAddr);
    obj.setValue(curValue);
    mCommandQueue.offer(obj);
}
